
package com.phm.phmneuron.generator;

import com.phm.phmneuron.NeuralNetwork;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author PARHAM
 */
public abstract class DataGenerator {
    protected NeuralNetwork _network = null;
    protected AtomicInteger _numGeneratedSignals = new AtomicInteger(0);
    
    public DataGenerator () {
        // Empty body
    }
    public DataGenerator (NeuralNetwork net) {
        _network = Objects.requireNonNull(net);
    }
    
    public int countGeneratedSignals () {
        return _numGeneratedSignals.get();
    }
    public float [] nextGeneratedSignal(){
        float [] temp = generate();
        if (temp != null) {
            _numGeneratedSignals.incrementAndGet();
        }
        return temp;
    }
    public List<float []> nextGeneratedSignals (int num) {
        if (num <= 0) return null;
        ArrayList<float []> arr = new ArrayList<>(num);
        for (int index = 0; index < num; index++) {
            float [] temp = nextGeneratedSignal();
            if (temp != null) {
                arr.add(temp);
            }
        }
        return arr;
    }
    
    protected abstract float [] generate ();
    public abstract int countRemainSignals ();
    public abstract boolean hasMoreElement ();
    public abstract void reset ();
}
